﻿using SqlSugar;
using System.Linq.Expressions;

namespace Zy.Shared.Repository.ClickHouse.Repositorys
{
    /// <summary>
    /// SqlSugar库
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface ISqlSugarRespository<TEntity> where TEntity : SqlSugarEntity, new ()
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> InsertAsync(TEntity entity);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> InsertAsync(List<TEntity> entities);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        IInsertable<TEntity> Insertable(List<TEntity> entities);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        IInsertable<TEntity> Insertable(TEntity entity);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(TEntity entity);
        Task<int> UpdateAsync(List<TEntity> entities);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="expression">修改数据的查询条件</param>
        /// <param name="columns">要修改的列</param>
        /// <returns></returns>
        Task<int> UpdateAsync(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> expression);
        Task<int> UpdateAsync(List<TEntity> entity, Expression<Func<TEntity, object>> updateColumns);
        IUpdateable<TEntity> Updateable(TEntity entity);
        IUpdateable<TEntity> Updateable(List<TEntity> entity, Expression<Func<TEntity, object>> updateColumns, Expression<Func<TEntity, bool>> expression);
        IUpdateable<TEntity> Updateable(List<TEntity> entity, Expression<Func<TEntity, bool>> expression);
        IUpdateable<TEntity> Updateable(List<TEntity> entity, Expression<Func<TEntity, object>> updateColumns);
        Task<int> DeleteAsync(Expression<Func<TEntity, bool>> expression);
        IDeleteable<TEntity> Deleteable(Expression<Func<TEntity, bool>> expression);
        ISugarQueryable<TEntity> SqlQueryable(string sql);
        ISugarQueryable<TEntity> Queryable();
        ISugarQueryable<TEntity> Queryable(Expression<Func<TEntity, bool>> expression);
        ISugarQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> expression);
        Task<List<TEntity>> SqlQueryAsync(string sql);
        Task<int> CountAsync(Expression<Func<TEntity, bool>> expression);
        Task<TResult> FetchAsync<TResult>(Expression<Func<TEntity, TResult>> selector, Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression = null);
    }
}
